<template>
  <div>
    <el-table
      :data="proList"
      style="width: 100%">
      <el-table-column
        type="index"
        label="序号"
        :index="index">
      </el-table-column>
      <el-table-column
        prop="proname"
        label="产品名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="originprice"
        label="产品价格"
        width="180">
      </el-table-column>
      <el-table-column
        prop="img1"
        label="图片">
        <template #default="scope">
         <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.img1"
            :fit="fit"></el-image>
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
        <template #default="scope">
           <el-button type="warning">编辑</el-button>
           <el-button type="danger" @click="delItem(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { defineComponent, onMounted, ref } from "vue";
import { getProList, delProItem } from "../../api/pro";

export default defineComponent({
  setup () {
    const proList = ref([])

    onMounted(() => {
      getProList().then(res => {
        console.log(res)
        proList.value = res
      })
    })
    function delItem (id) {
      console.log(id)
      delProItem(id).then((r) => {
        console.log(r)
        getProList().then(res => {
          console.log(res)
          proList.value = res
        })
      })
    }
    return {
      proList,
      delItem
    }
  }
})
</script>